package com.example.dqdq.lzyim_asm_tvapp;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.example.dqdq.lzyim_asm_tvapp.receiver.AdTextReceiver;
import com.example.dqdq.lzyim_asm_tvapp.utils.ActivityCollector;

import java.util.Calendar;

/**
 * Created by DQDQ on 2016/10/15.
 */

public class StartServerActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent=getIntent();

        ActivityCollector.finishAll(this);
        int nunmber=intent.getIntExtra("number",0);
        Log.e("Test number",String.valueOf(nunmber));

        String content=intent.getStringExtra("content");
        String imgpath=intent.getStringExtra("imgpath");

        addAdText(nunmber,20,content,imgpath);
        finish();
    }

    public void addAdText(int number, int time,String content,String imgpath)
    {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(System.currentTimeMillis());
        cal.add(Calendar.SECOND, (int) time);
        Activity activity = this;
        Intent intent = new Intent(activity, AdTextReceiver.class);
        intent.setClass(activity, AdTextReceiver.class);
        intent.putExtra("msg", "play_hskay");
        intent.putExtra("number", number);
        intent.putExtra("content", content);
        intent.putExtra("imgpath", imgpath);

        PendingIntent pi = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        AlarmManager am = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
